package com.sangeng.controller;

import com.sangeng.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {


    @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
    public String findUserById(@PathVariable("id") Integer id) {
        System.out.println("findUserById");
        System.out.println(id);
        return "/success.jsp";
    }


    @RequestMapping(value = "/user/{id}/{name}", method = RequestMethod.GET)
    public String findUserByUserId(@PathVariable("id") Integer id, @PathVariable("name") String name) {
        System.out.println(id + name);
        System.out.println("findUserByUserId");
        return "/success.jsp";
    }


    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public String insertUser(@RequestBody Map map) {
        System.out.println("insertUser");
        System.out.println(map);
        return "/success.jsp";
    }

    @RequestMapping(value = "/users", method = RequestMethod.POST,params = "name!=yangchen")
    public String insertUsers(@RequestBody List<User> list) {
        System.out.println("insertUsers");
        for (User user : list) {
            System.out.println(user);
        }
        return "/success.jsp";
    }


    @RequestMapping(value = "/testRequestParam",params = "name!=yangchen")
    public String testRequestParam(@RequestParam(value = "id",required = false) Integer id, @RequestParam("name") String name, @RequestParam("likes") String[] likes) {
        System.out.println("testRequestParam");
        System.out.println(id);
        System.out.println(name);
        System.out.println(Arrays.toString(likes));
        return "/success.jsp";
    }

//    @RequestMapping(value = "/testRequestParam")
//    public String testRequestParam( Map map) {
//        System.out.println("testRequestParam");
//        System.out.println(map);
//        return "/success.jsp";
//    }

}
